<?php
/**
 * Joomla! 1.5 component Bbits Simple directory
 *
 * @version $Id: view.html.php 2011-07-08 03:53:16 svn $
 * @author Miguel Puig
 * @URL http://miguelpuig.com
 * @package Joomla
 * @subpackage Bbits Simple directory
 * @license GNU/GPL
 *
 * Simple Directory by bittingbits.com
 *
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.controller' );
require_once( JPATH_COMPONENT.DS.'helpers'.DS.'helper.php' );

/**
 * Bbits Simple directory Controller
 *
 * @package Joomla
 * @subpackage Bbits Simple directory
 */
class BbitsdControllerGroups extends JController {
    /**
     * Constructor
     * @access private
     * @subpackage Bbits Simple directory
     */
   function __construct() {
    //Get View
    if(JRequest::getCmd('view') == '') {
        JRequest::setVar('view', 'default');
    }
    $this->item_group = 'Default';
    parent::__construct();
    
    $this->registerTask('addGroup', 'editGroup');
    
    }
     
   function groups()
   {
        JRequest::setVar('view', 'groups');
        parent::display();
   }
   
   function editGroup()
    {
        JRequest::setVar('view', 'editGroup');
        JRequest::setVar('hidemainmenu', 1);
        
        $model = $this->getModel('groups');
        $user =& JFactory::getUser();
        
        $view =& $this->getView('editGroup', 'html');
        $view->setModel($this->getModel('groups'), true);

        
        $view->display();
        
    }
    function saveGroup() {
        $model = $this->getModel('groups');
        $user =& JFactory::getUser();
        
        // applying all changes
        $id = $model->store();

    
        $link 	= 'index.php?option=com_bbitsd&view=groups';
        $this->setRedirect($link, JText::_('COM_BBSDIR_GROUP_SAVED'));
    }
   function applygroup()
    {
        JRequest::setVar('view', 'editGroup');
        JRequest::setVar('hidemainmenu', 1);
        
        $model = $this->getModel('groups');

        $user =& JFactory::getUser();

        $id = $model->store();

        JRequest::setVar('cid', array($id));

        $view =& $this->getView('editGroup', 'html');
        $view->setModel($this->getModel('groups'), true);
        
        $view->display();
    } 
   function deleteGroup()
    {
        $model = $this->getModel('groups');
        $cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
        
        if (!is_array($cid) || count($cid) < 1) {
            $msg = '';
			JError::raiseWarning(500, JText::_( 'COM_BBSDIR_SELECT_DELETE' ) );
        } else {
            foreach ($cid as $id) {
                if (!$model->delete($id)) {
                    JError::raiseError(500, JText::_('COM_BBSDIR_DELETE_FAILED').'<pre>'.print_r($cid, true).'</pre>');
                }
            }
            
            $msg = count($cid).' '.JText::_( 'COM_BBSDIR_SELECTED_DELETE' );
			$cache = &JFactory::getCache('com_bbitsd');
			$cache->clean();
        }
        
        $this->setRedirect( 'index.php?option=com_bbitsd&view=groups', $msg );
    }
    
    function publish() {
           $cid = JRequest::getVar('cid', array(), 'default', 'array');

           $model = & $this->getModel('groups');
           $model->publishList($cid, 1);

           $this->setRedirect( 'index.php?option=com_bbitsd&view=groups');
    }

    function unpublish() {
           $cid = JRequest::getVar('cid', array(), 'default', 'array');

           $model = & $this->getModel('groups');
           $model->publishList($cid, 0);
           $this->setRedirect( 'index.php?option=com_bbitsd&view=groups');
    } 
    
}
?>